Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

relative

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relative

Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file, and directory-to-directory.

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
385K
increased by1.72%
Maintainers
1
Weekly downloads
 
Created
Source

relative NPM version

Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file, and directory-to-directory.

Calculates correctly from:

  • File to directory
  • File to file
  • Directory to file
  • Directory to directory

Install with npm

npm i relative --save

Usage

var relative = require('relative');
relative(from, to);

// Example
relative('test/fixtures/foo.txt', 'docs');
// => '../../docs'

API

relative

Return the relative path from a to b.

  • from {String}
  • to {String}
  • returns: {String}

Example:

var relative = require('relative');
relative('a/b/foo.txt', 'c/d/file.txt');
//=> '../../c/d/file.txt'

.toBase

Get the path relative to the given base path.

  • base {String}: The base directory
  • fp {String}: The full filepath
  • returns {String}: The relative path

Example:

relative.toBase('a/b', 'a/b/c/d/file.txt');
//=> 'c/d/file.txt'

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license


This file was generated by verb on December 25, 2014.

Keywords

FAQs

Package last updated on 25 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc